package com.hebang.stcommunityapp.adapters;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hebang.stcommunityapp.beans.SyItemBean;
import com.hebang.stcommunityapp.custom.DeviceItemView;
import com.hebang.stcommunityapp.custom.SyItemView;
import com.hebang.stcommunityapp.holders.BaseCustomHoder;

import java.util.List;

public class DeviceListdapter extends RecyclerView.Adapter<BaseCustomHoder> implements View.OnClickListener {
    List<SyItemBean> list;

    public DeviceListdapter(List<SyItemBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        DeviceItemView view = new DeviceItemView(parent.getContext());
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseCustomHoder holder, final int position) {
        holder.itemView.setTag(position);
        holder.bind(list.get(position));
        holder.itemView.setOnClickListener(this);
//        if (holder instanceof MyViewHolder) {
//            ((MyViewHolder) holder).binding.setProBean(list.get(position));
//            ((MyViewHolder) holder).binding.tianbaoLiner.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (mOnItemClickListener != null) {
//                        mOnItemClickListener.onTianbaoClick(v,position);
//                    }
//                }
//            });
//            ((MyViewHolder) holder).binding.nigaoLiner.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (mOnItemClickListener != null) {
//                        mOnItemClickListener.onNigaoClick(v,position);
//                    }
//                }
//            });
//            ((MyViewHolder) holder).binding.shenpiLiner.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (mOnItemClickListener != null) {
//                        mOnItemClickListener.onShenpiClick(v,position);
//                    }
//                }
//            });
//        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onClick(v, (Integer)v.getTag());
        }
    }


    private OnItemClickListener mOnItemClickListener;

    /**
     * interface。
     */
    public static interface OnItemClickListener {
        void onClick(View view, int position);

    }

    /**
     * 设置Adapter的Item监听事件。外部通过实现这个方法来获取监听。
     */
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    class MyViewHolder extends BaseCustomHoder {
        DeviceItemView paramFromView;

        public MyViewHolder(DeviceItemView paramFromView) {
            super(paramFromView);
            this.paramFromView = paramFromView;
        }
    }
}
